import { configureStore } from '@reduxjs/toolkit'
import userReducer, { UserStateType } from './features/user'
import componentsReducer, { ComponentsStateType } from './features/componentsReducer'
import pageReducer, { PageInfoStateType } from './features/pageReducer'
import undoable, { excludeAction, StateWithHistory } from 'redux-undo'

export type StateType = {
  user: UserStateType
  // components: ComponentsStateType
  components: StateWithHistory<ComponentsStateType> //增加了undo
  page: PageInfoStateType
}

export default configureStore({
  reducer: {
    //分模块
    user: userReducer,
    //组件列表
    //没有undo
    // components: componentsReducer,

    //增加了undo
    components: undoable(componentsReducer, {
      limit: 20,
      filter: excludeAction([
        'components/resetComponents',
        'components/changeSelectedId',
        'components/selectPrevComponent',
        'components/selectNextComponent',
      ]),
    }),

    //页面信息
    page: pageReducer,
  },
})
